/**      
 * @file		danglingPtr.cpp
 * @description		This demonstrates dangling pointers. Dangling
 *			pointers can be frustrating and hard to debug.
 *			Make sure that you don't assign multiple pointers
 *			to the same data, remove the data and then try to reference
 *			the data with another pointer. This application throws
 *			a runtime error because of line 37.
 * @course		CSCI 123 Section 00000
 * @assignment 
 * @date		mm/dd/yyyy
 * @author		Brad Rippe (00000000) brippe@fullcoll.edu
 * @version		1.0
 */
#include <iostream>
using namespace std;

/**
 * @return zero if the application executes successfully
 */
int main() {
	int v1 = 22;

	// declare a pointer variable
	int *p1;

	// set ptr1 to the address of v1
	p1 = &v1;

	// declare and assign ptr2 the same address as ptr1
	int *p2 = p1;

	// output the value by dereferencing the ptrs
	cout << "*p1 == " << *p1 << endl;
	cout << "*p2 == " << *p2 << endl;

	cout << "deleting *p1!\n";
	delete p1;

	// this line will cause a runtime error
	// because when p1 was deleted p2 was also
	// deleted
	cout << "*p2 == " << *p2 << endl;

	return 0;
}
